#include <bits/stdc++.h>
using namespace std;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t, n, m, changdu, xiansu, st[100002], sd[100002], jsd, y, sum=0;
    cin>>t;
    for(int j=0;j<t;j++){
        cin>>n>>m>>changdu>>xiansu;
        for(int i=0;i<n;i++){
            cin>>st[i]>>sd[i]>>jsd;
        }
        for(int i=0;i<m;i++) cin>>y;
        for(int i=0;i<n;i++){
            if(y>=st[i]&&xiansu<sd[i]) sum++;
        }
        printf("%d %d\n",sum, sum?m-1:m);
        sum=0;
    }
    return 0;
}
